package basic

import (
	"chat/app/common"
	"chat/app/dao"
	"context"
)

// UserAuth 验证用户是否有效
func UserAuth(ctx context.Context, userId int64) map[string]any {

	// 创建返回信息
	data := make(map[string]map[string]any)
	code := common.INVALID_PARAMS

	// 验证用户
	resultData, isExist := dao.UserGetById(userId)
	//log.Printf("resultData: %#v", resultData)
	if isExist {
		data["userInfo"] = make(map[string]any)
		data["userInfo"]["uid"] = resultData.Id
		data["userInfo"]["mobile"] = resultData.Mobile
		data["userInfo"]["nickname"] = resultData.Nickname
		data["userInfo"]["avatar"] = resultData.Avatar
		data["userInfo"]["sex"] = resultData.Sex
		data["userInfo"]["remark"] = resultData.Memo
		data["userInfo"]["token"] = resultData.Token
		code = common.SUCCESS
	} else {
		code = common.ERROR_AUTH
	}

	return common.Response(code, common.GetMsg(code), data)
}
